﻿#region

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Vin.Extension.HttpLogging.Config;
using Vin.Tool.AspNetCore.Singleton;

#endregion

namespace Vin.Extension.HttpLogging;

[Order(0)]
public class ExtensionEntry : IVinExtension
{
    public void AddVinExtension(WebApplicationBuilder builder)
    {
        // builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, VinHttpLoggingProvider>());
        
        #region 使用HttpLogging

        builder.Services.AddHttpLogging(options =>
        {
            var config = VinApp.GetService<IOptionsMonitor<VinHttpLoggingConfig>>();
            if (config != null)
            {
                options.LoggingFields = config.CurrentValue.LoggingFields;
                options.CombineLogs = config.CurrentValue.CombineLogs;
            }
        });

        // builder.Services.AddHttpLoggingInterceptor<VinHttpLoggingInterceptor>();

        #endregion
    }

    public void AddVinExtension(IServiceCollection services)
    {
    }

    public void UseVinExtension(WebApplication app)
    {
        app.UseHttpLogging();
    }
}